﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Engine.Dtd.Configuration {
    /// <summary>
    /// Provides access to the entity collection in a configuration file.
    /// </summary>
    public sealed class PublicEntityCollection : ConfigurationElementCollection {
        /// <summary>
        /// Creates a new EntityConfigurationElement.
        /// </summary>
        /// <returns>A new EntityConfigurationElement.</returns>
        protected override ConfigurationElement CreateNewElement() {
            return new PublicElement();
            }

        /// <summary>
        /// Adds a entity configuration element to this collection.
        /// </summary>
        /// <param name="element">An entity configuration element to add.</param>
        public void Add(PublicElement element) {
            Guard.ArgumentNotNull(element, "element");
            BaseAdd(element, true);
            }

        /// <summary>
        /// Returns an EntityConfigurationElement with the specified public identifier.
        /// </summary>
        /// <param name="publicId">A string that contains the public identifier.</param>
        /// <returns>The EntityConfigurationElement object with the specified public ID; otherwise null.</returns>
        public new PublicElement this[string publicId] {
            get {
                Guard.ArgumentNotNullOrWhitespace(publicId, "publicId");
                return (PublicElement)BaseGet(publicId);
                }
            }

        /// <summary>
        /// Gets the public ID as a key for a specified configuration element.
        /// </summary>
        /// <param name="element">The EntityConfigurationElement to return the key for.</param>
        /// <returns>An System.Object that acts as the key for the specified EntityConfigurationElement.</returns>
        protected override object GetElementKey(ConfigurationElement element) {
            return ((PublicElement)element).PublicId;
            }
        }
    }
